package com.foreknow.elm.controller;

import com.foreknow.elm.po.Deliveryaddress;
import com.foreknow.elm.service.DeliveryaddressService;
import com.foreknow.elm.service.impl.DeliveryaddressServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class DeliveryAddressController {
    public Object listDeliveryAddressByUserId(HttpServletRequest request){
        String userId = request.getParameter("userId");
        DeliveryaddressService deliveryaddress = new DeliveryaddressServiceImpl();
        List<Deliveryaddress> list = deliveryaddress.slistDeliveryAddressByUserId(userId);
        return list;
    };

    public Object getDeliveryAddressById(HttpServletRequest request){
        Integer daid = Integer.valueOf(request.getParameter("daId"));
        DeliveryaddressService deliveryaddress = new DeliveryaddressServiceImpl();
        Deliveryaddress list = deliveryaddress.sgetDeliveryAddressById(daid);
        return list;
    };

    public Object saveDeliveryAddress(HttpServletRequest request){
        String contactName = request.getParameter("contactName");
        Integer contactSex = Integer.valueOf(request.getParameter("contactSex"));
        String contactTel = request.getParameter("contactTel");
        String address = request.getParameter("address");
        String userId = request.getParameter("userId");
        Deliveryaddress deliveryaddress = new Deliveryaddress();
        deliveryaddress.setContactName(contactName);
        deliveryaddress.setContactSex(contactSex);
        deliveryaddress.setContactTel(contactTel);
        deliveryaddress.setAddress(address);
        deliveryaddress.setUserId(userId);
        DeliveryaddressService deliveryaddressService = new DeliveryaddressServiceImpl();
        int isRight = deliveryaddressService.dsaveDeliveryAddress(deliveryaddress);
        return isRight;
    };

    public Object updateDeliveryAddress (HttpServletRequest request){
        Integer daId = Integer.valueOf(request.getParameter("daId"));
        String contactName = request.getParameter("contactName");
        Integer contactSex = Integer.valueOf(request.getParameter("contactSex"));
        String contactTel = request.getParameter("contactTel");
        String address = request.getParameter("address");
        String userId = request.getParameter("userId");
        Deliveryaddress deliveryaddress = new Deliveryaddress();
        deliveryaddress.setContactName(contactName);
        deliveryaddress.setContactSex(contactSex);
        deliveryaddress.setContactTel(contactTel);
        deliveryaddress.setAddress(address);
        deliveryaddress.setUserId(userId);
        deliveryaddress.setDaId(daId);
        DeliveryaddressService deliveryaddressService = new DeliveryaddressServiceImpl();
        int isRight = deliveryaddressService.dupdateDeliveryAddress(deliveryaddress);
        return isRight;
    };

    public Object removeDeliveryAddress (HttpServletRequest request){
        Integer daId = Integer.valueOf(request.getParameter("daId"));
        DeliveryaddressService deliveryaddressService = new DeliveryaddressServiceImpl();
        int isRight = deliveryaddressService.dremoveDeliveryAddress(daId);
        return isRight;
    };
}
